package logic

import (
	"context"
	"taobao-merchandis/taobaorpc/taobaorpc"

	"taobao-merchandis/api/internal/svc"
	"taobao-merchandis/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type PuDataLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewPuDataLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PuDataLogic {
	return &PuDataLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *PuDataLogic) PuData(req *types.PuDataRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	updata, err := l.svcCtx.TaoBaoRpc.UpData(l.ctx, &taobaorpc.UpDataRequest{
		Title:   req.Title,
		Price:   float32(req.Price),
		Image:   req.Image,
		UserId:  req.UserId,
		GoodsId: req.GoodsId,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}
	return &types.Response{
		Message: "修改成功",
		Data:    updata,
		Code:    200,
	}, nil
}
